package websocket.dto;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @ClassName ResultPage
 * @Des TODO
 * @Author lg
 * @Date 2022/3/6 19:04
 * @Version 1.0.0
 **/
@ApiModel(value = "数据返回-分页数据")
@JsonNaming(value = PropertyNamingStrategy.SnakeCaseStrategy.class)
public class ResultPage<T> implements Serializable {
    /**
     * 状态值
     */
    @ApiModelProperty(name = "code", value = "状态值:0 – 处理成功，403 - 鉴权失败，500 - 系统错误，503 - 参数错误")
    private Integer code;

    /**
     * 提示
     */
    @ApiModelProperty(name = "message", value = "提示")
    private String message;

    /**
     * 返回数据
     */
    @ApiModelProperty(name = "data", value = "返回数据")
    private PageDTO<T> data ;

    private ResultPage(ResultEnum resCode, PageDTO<T> data) {
        this.code = resCode.getCode();
        this.message = resCode.getMessage();
        this.data = data;
    }


    /**
     * 请求成功
     * @param data 数据
     * @param <T>
     * @return
     */
    public static <T> ResultPage<T> success(PageDTO<T> data) {
        return new ResultPage<T>(ResultEnum.success, data);
    }

    /**
     * 请求失败,系统异常
     * @param <T>
     * @return
     */
    public static <T> ResultPage<T> systemError() {
        return new ResultPage<T>(ResultEnum.SYSTEM_ERROR,null);
    }

    /**
     * 请求失败,参数错误
     * @param <T>
     * @return
     */
    public static <T>  ResultPage<T> paramError() {
        return new ResultPage<T>(ResultEnum.PARAM_ERROR,null);
    }
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public PageDTO<T> getData() {
        return data;
    }

    public void setData(PageDTO<T> data) {
        this.data = data;
    }
}

